import {
  exportUrl,
  getListByType,
  getListArea,
  queryPageByGroupType,
} from "@/api/checkorder/mesOrderCheckTemplate";
import { getDict } from "@/api/common";
import { getCurrentWarehouseCode } from "@/api/inbound/mesInTask";
// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t("common.export"),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
  },
  {
    name: $i18n.t("common.add"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "add", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    icon: "el-icon-delete",
    handleName: "deleteBatch", //点击时返回的标识
    isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
  },

  {
    name: $i18n.t("创建盘点单"),
    type: "primary",
    icon: "el-icon-circle-plus-outline",
    handleName: "createTask", //点击时返回的标识
    isSingle: true,
    disabled: (data) => !(data.length == 1),
  },
  {
    name: $i18n.t("启用"),
    type: "success",
    icon: "el-icon-circle-plus-outline",
    handleName: "enabled", //点击时返回的标识
    isSingle: true,
    disabled: (data) => !(data.length == 1 && data[0].enableStatus == "0"),
  },

  {
    name: $i18n.t("停用"),
    type: "danger",
    icon: "el-icon-circle-plus-outline",
    handleName: "deactivated", //点击时返回的标识
    isSingle: true,
    disabled: (data) => !(data.length == 1 && data[0].enableStatus == "1"),
  },
  // {
  //   name: $i18n.t("common.import"),
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "import" //点击时返回的标识
  // }
];
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    templateName: {
      type: "input",
      label: "盘点模板", // 模板名称
    },
  },
};
import { uniqueKey } from "@/utils/judge";
import {getUserListByRoleIdAndFactory} from "@/api/user";
// 新增/删除表单配置
export const formConfig = {
  methods: {
    changeTemplateType(val) {
      if (val == "20") {
        this.$set(this.formDescDialog.formDesc.dpFlag, "disabled", true);
        this.$set(this.formDataDialog, "dpFlag", 0);
      } else {
        this.$set(this.formDescDialog.formDesc.dpFlag, "disabled", false);
      }
    },
    openMaterialModal(type) {
      const {
        locationRestrictions,
        materialRestrictions,
      } = this.formDataDialog;
        this.modalTitle = materialRestrictions === "20" ? "物料" : "物料组";
        this.otherParam = { groupType: materialRestrictions };
        this.goodsDialogColumn =
          materialRestrictions === "20"
            ? this.goodsColumns1
            : this.goodsColumns2;
        this.goodsSearchDialog =
          materialRestrictions === "20" ? this.goodsSearch1 : this.goodsSearch2;
        this.goodsDialogVisible = true;

    },
    getSelectplaceData(data) {
      const { locationRestrictions } = this.formDataDialog;
      let list = [
        ...(this.formDataDialog?.table1 ?? []),
        ...data.map((ite) => {
          return locationRestrictions == "20"
            ? {
                code: ite.areaCode,
                name: ite.areaDesc,
              }
            : locationRestrictions == "30"
            ? {
                code: ite.locationCode,
                name: ite.locationCode,
              }
            : {
                code: ite.locationGroupCode,
                name: ite.locationGroupCode,
              };
        }),
      ];
      // 筛选重复值,插入
      this.$set(this.formDataDialog, "table1", uniqueKey(list, "code"));
    },
    getSelectData(data) {
      const { materialRestrictions } = this.formDataDialog;
      let list = [
        ...(this.formDataDialog?.table2 ?? []),
        ...data.map((ite) => {
          return materialRestrictions == "20"
            ? {
                code: ite.goodsCode,
                name: ite.goodsName,
              }
            : {
                code: ite.seriesCode,
                name: ite.seriesName,
              };
        }),
      ];

      // 筛选重复值,插入
      this.$set(this.formDataDialog, "table2", uniqueKey(list, "code"));
    },
    deleteRow(index, table) {
      table.splice(index, 1);
    },
  },
  data() {
    const that = this;
    return {
      placeDialogColumn: [],
      placeDialogVisible: false,
      placeSearchDialog: {},
      areaColumn: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          prop: "areaCode",
          label: $i18n.t("common.areaCode"),

          showOverflowTooltip: true,
        },
        {
          prop: "areaDesc",
          label: $i18n.t("common.areaName"),

          showOverflowTooltip: true,
        },
      ],
      locationColumn: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          prop: "warehouseCode",
          label: $i18n.t("common.warehouse"),

          optionProp: {
            value: "modelingCode",
            label: "modelingName",
          },
          option: async (data) => {
            const list = await getCurrentWarehouseCode();
            return list.data.result;
          },
          showOverflowTooltip: true,
        },
        {
          prop: "locationCode",
          label: $i18n.t("common.location"),

          showOverflowTooltip: true,
        },
      ],
      locationGroupColumn: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          prop: "warehouseCode",
          label: $i18n.t("common.warehouse"),

          optionProp: {
            value: "modelingCode",
            label: "modelingName",
          },
          option: async (data) => {
            const list = await getCurrentWarehouseCode();
            return list.data.result;
          },
          showOverflowTooltip: true,
        },
        {
          prop: "locationGroupCode",
          label: $i18n.t("wmsOrderCheckTemplate.locationGroup"),

          showOverflowTooltip: true,
        },
      ],
      areaSearchDialog: {
        inline: true,
        formDesc: {
          areaCode: {
            type: "input",
            label: $i18n.t("common.areaCode"),
          },
          areaDesc: {
            type: "input",
            label: $i18n.t("common.areaName"),
          },
        },
      },
      locationGroupDialog: {
        inline: true,
        formDesc: {
          // warehouseCode: {
          //   type: "select",

          //   label: $i18n.t("common.warehouse"),
          //   prop: {
          //     value: "modelingCode",
          //     text: "modelingName"
          //   },
          //   options: async (data) => {
          //     const res = await getCurrentWarehouseCode()
          //     let list = res.data.result || []

          //     return list
          //   }
          // },
          locationGroupCode: {
            type: "input",
            label: $i18n.t("wmsOrderCheckTemplate.locationGroup"),
          },
        },
      },
      locationSearchDialog: {
        inline: true,
        formDesc: {
          // warehouseCode: {
          //   type: "select",

          //   label: $i18n.t("common.warehouse"),
          //   prop: {
          //     value: "modelingCode",
          //     text: "modelingName"
          //   },
          //   options: async (data) => {
          //     const res = await getCurrentWarehouseCode()
          //     let list = res.data.result || []

          //     return list
          //   }
          // },
          locationCode: {
            type: "input",
            label: $i18n.t("common.locationCode"),
          },
        },
      },
      goodsSearch1: {
        inline: true,
        formDesc: {
          goodsCode: {
            type: "input",
            label: $i18n.t("common.materialCode"),
          },
          goodsName: {
            type: "input",
            label: $i18n.t("common.materialName"),
          },
        },
      },
      goodsSearch2: {
        inline: true,
        formDesc: {
          seriesName: {
            type: "input",
            label: "分组名称",
          },
        },
      },
      goodsColumns1: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          prop: "goodsCode",
          label: $i18n.t("common.materialCode"),

          showOverflowTooltip: true,
        },
        {
          prop: "goodsName",
          label: $i18n.t("common.materialName"),

          showOverflowTooltip: true,
        },
      ],
      goodsColumns2: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          prop: "seriesName",
          label: "分组名称",
          showOverflowTooltip: true,
        },
      ],
      goodsDialogVisible: false,
      goodsSearchDialog: {},
      goodsDialogColumn: [],
      otherParam: {},
      getListByType,
      getPlaceList: null,
      formDescDialog: {
        span: 24,
        disabled: false,
        labelPosition: "top",
        isShowSubmitBtn: true,
        isShowErrorNotify: false,
        formDesc: {
          templateName: {
            type: "input",
            label: "盘点模板", // 模板名称
            layout: 12,
            disabled: (d) => !!d.id,
          },
          warehouseCode: {
            type: "select",
            layout: 12,
            label: $i18n.t("common.warehouse"),
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },

            options: async (data) => {
              const res = await getCurrentWarehouseCode();
              let list = res.data.result || [];

              return list;
            },
            required: true,
          },
          mpFlag: {
            type: "switch",
            label: "是否盲盘", // 是否盲盘
            layout: 12,
            required: false,
            //提交时将true 转化为1 false 0
            valueFormatter(labels) {
              return labels ? 1 : 0;
            },
            //展示时字段转化
            displayFormatter(labels) {
              return labels == 1 ? true : false;
            },
          },
          enableStatus: {
            type: "switch",
            label: "是否启用", // 是否启用
            layout: 12,
            // required: false,
            //提交时将true 转化为1 false 0
            valueFormatter(labels) {
              if (typeof labels == "boolean") {
                return labels ? "1" : "0";
              } else {
                return labels == "1" ? "1" : "0";
              }
            },
            //展示时字段转化
            displayFormatter(labels) {
              if (typeof labels == "boolean") {
                return labels ? true : false;
              } else {
                return labels == "1" ? true : false;
              }
            },
            required: true,
          },
          table2: {
            label: "",
            type: "text",
            layout: 24,
          },
          isAppoint: {
            type: "switch",
            label: "是否指定盘点人", // 是否指定盘点人
            layout: 12,
            required: false,
            //提交时将true 转化为1 false 0
            valueFormatter(labels) {
              if (typeof labels == "boolean") {
                return labels ? "1" : "0";
              } else {
                return labels == "1" ? "1" : "0";
              }
            },
            //展示时字段转化
            displayFormatter(labels) {
              if (typeof labels == "boolean") {
                return labels ? true : false;
              } else {
                return labels == "1" ? true : false;
              }
            },
            // required: true,
          },
          table3: {
            label: "",
            type: "text",
            layout: 24,
          },
          remark: {
            label: $i18n.t("common.remark"),
            type: "textarea",
            layout: 24,
            attrs: {
              rows: 1,
              autosize: true,
            },
          },
        },
      },
    };
  },
};
export const userMixin = {
  data() {
    return {
      baseUserDialogVisible: false,
      baseUserSearchDialog: {
        inline: true,
        formDesc: {
          nickName: {
            type: "input",
            layout: 8,
            label: $i18n.t("用户昵称") //"用户昵称"
          }
        }
      },
      baseUserDialogColumn: [
        {
          type: "selection"
        },

        // {
        //   prop: "tenantCode",
        //   label: $i18n.t("users.tenantCode") //"租户编码"
        // },
        {
          prop: "jobNumber",
          label: $i18n.t("工号") //"工号"
        },
        {
          prop: "nickName",
          label: $i18n.t("用户昵称") //"用户昵称"
        },
        {
          prop: "email",
          label: $i18n.t("用户邮箱") //"用户邮箱"
        },
        {
          prop: "mobile",
          label: $i18n.t("手机号码") //"手机号码"
        }
      ],
      getUserListByRoleIdAndFactory
    }

  },
  methods: {
    getSelectBaseUser(data) {
      console.log(data)
      this.$set(this.formDataDialog, "personName",  data.map((item)=> item.nickName).join(","))
      this.$set(this.formDataDialog, "personCode", data.map((item)=> item.jobNumber ).join(","))
    },

  }
}
